/*

Enables basic shop functionality in the level.

Sells arrows and bombs for 100 gralats.

Usage (Level NPC):

function onCreated() {
  this.join("shop_basic");
}

*/

function onPlayerChats() {
  if (player.chat == "buy bombs") {
    buyBombs();
  }
  else if (player.chat == "buy arrows") {
    buyArrows();
  }
}

function buyBombs() {
  if (hasGralats(10)) {
    player.rupees -= 10;
    player.bombs += 5;
    player.chat = "Purchased 5 Bombs!";
  }
  else insufficientRupees(10);
}

function buyArrows() {
  if (hasGralats(10)) {
    player.rupees -= 10;
    player.darts += 10;
    player.chat = "Purchased 10 Arrows!";
  }
  else insufficientRupees(10);
}

function insufficientRupees(amount) {
  player.chat = format("You need %s rupees!", amount);
}

function hasGralats(amount) {
  return (player.rupees >= amount);
}
